{
	var rebind=getURLParameter("rebind");
	if(rebind!=null&&typeof(rebind)!='undefined'&&eval(rebind)){
		bindSinaSNS();
		
	}else{
		
		var state=getURLParameter("state");
		if(state!=null&&typeof(state)!='undefined'&&state=='sina'){
			var code=getURLParameter("code");
			jQ.ajax({
				type: "POST",
				url:"userAjax!userBindSinacode.action",
				data:{
					code:code
				},
				async:false,
				success:function(data){
					if(data.result){
						var url=data.trun2url;
						if(url!=null&&url.length>0){
							window.location.href=url;
						}else
							window.location.href="./ccinfo.html";
					}else{
						alert(data.errormsg);
						window.location.href="./ccinfo.html";
					}
				}
			});
		}
	}
}

function getURLParameter(name){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=unescape(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.length==0)return null;
    var params=paramStr.split('&');
    var p = null;
    for(var i=0;i<params.length;i++){
        if(params[i].indexOf(name) >= 0){
            p = params[i].split('=');
            if(p[0]==jQ.trim(name))
            	p = p[1];
        }
    }
    return p;
}

jQ(function(){
	checkUrlCode();
	initCCUserInfo();
	
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				//activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
		},
		open:function(){
		}
	});
});



function initCCUserInfo(){
	jQ.ajax({
		type:"POST",
		url:"userAjax!getCCUserInfo.action",
		success:function(data){
//			alert(data);
//			return;
			if(data.result){
				var hasdemension=eval(data.hasdemension);
				var demensioncodeurl=data.demensioncodeurl;
				var username=data.username;
				var name=data.name;
				var desc=data.desc;
				var website=data.website;
				var emails=data.emails;
				var address=data.address;
				var addresscode=data.addresscode;
				var sufaddress=data.sufaddress;
				
//				var mobilenum=data.mobilenum;
//				var mobileisbindable=data.mobileisbindable;
				var isouter=data.isouter;
				
				jQ("#cc_username").empty().append(username);
				jQ("#cc_name").empty().append(name);
				jQ("#cc_desc").empty().append(desc);
				jQ("#cc_desc").data("value",desc);
				jQ("#cc_website").empty().append(website);
				jQ("#cc_website").data("value",website);
				jQ("#cc_address").empty().append(address);
				jQ("#cc_address").data("value",address);
				jQ("#cc_address").data("addresscode",addresscode);
				jQ("#cc_address").data("sufaddress",sufaddress);
				jQ("#demensioncodeimg").attr("src",demensioncodeurl);
//				if(mobilenum.length>0){
//					var mobileisbindablestr=eval(mobileisbindable)?"":" 未验证";
//					jQ("#cc_mobile").empty();
//					jQ("#cc_mobile").append(mobilenum+mobileisbindablestr);
//					jQ("#cc_mobile").data("mobilenum",mobilenum);
//					jQ("#cc_mobile").data("mobileisbindable",mobileisbindable);
//				}else{
//					jQ("#cc_mobile").empty().append("未绑定");
//					jQ("#cc_mobile").data("mobilenum","");
//				}
				jQ("#cc_isouter").find("label").nextAll().remove();
				if(isouter){
					var tmphtml="";
					tmphtml+="<div class=\"dostatus\">";
					tmphtml+="<span class=\"snsvalbox\">绑定账号：</span>";
					tmphtml+="<span class=\"snsinfo\">新浪微博</span>";
					tmphtml+="<i class=\"sinalogo\"></i>";
					tmphtml+="</div>";
					tmphtml+="<a class=\"unbindsns\">解除绑定微博账号</a>";
				}else{
					var tmphtml="";
					tmphtml+="<div class=\"undostatus\">";
					tmphtml+="<span class=\"snsvalbox\">您还未绑定社交账号</span>";
					tmphtml+="<a class=\"bindsns\"></a>";
					tmphtml+="</div>";
				}
				jQ("#cc_isouter").find("label").after(tmphtml);
				jQ("#cc_isouter div.undostatus").find("a.bindsns").bind("click",bindSinaSNS);
				jQ("#cc_isouter").find("a.unbindsns").bind("click",unbindSinaSNS);
//				jQ("#mobileupdate").bind("click",showMobileupdateinf);
				var contentHtml="";
				for(var i=0;i<data.emails.length;i++){
					var email=data.emails[i];
					var emailaddress=email.email;
					var checkstatus=email.checkstatus;
					var acceptstatus=email.acceptstatus;
					var emailid=email.emailid;
					
					contentHtml+="<fieldset class=\"add_mail pp\" id='email_"+emailid+"'>";
					if(checkstatus==1)
						contentHtml+="<legend>绑定邮箱</legend>";
					else
						contentHtml+="<legend>未验证邮箱</legend>";
					contentHtml+="<ul emailid="+emailid+">";

					contentHtml+="<li  class='email'>";
					contentHtml+="<label>邮箱：</label>";
					contentHtml+="<span class=\"emailval\">"+emailaddress+"</span>";
					contentHtml+="</li>";
					
					if(eval(checkstatus)==1){
						contentHtml+="<li status='"+acceptstatus+"'>";
						if(eval(acceptstatus)==1)
							contentHtml+="<input type=\"checkbox\" checked=\"checked\" disabled='disabled'>";
						else
							contentHtml+="<input type=\"checkbox\" disabled='disabled'>";
						contentHtml+="<span>是否设置为接收邮箱</span>";
						contentHtml+="</li>";
					}else{
						contentHtml+="<li>";
						contentHtml+="<span class='info'>邮箱地址需要验证</span>";
						contentHtml+="</li>";
					}
					contentHtml+="<li><a onclick=\"deleteEmail(this)\">删除</a>";
					if(eval(checkstatus)==1){
						contentHtml+="<a onclick=\"editEmail(this)\">编辑</a>";
					}else{
						contentHtml+="<a onclick=\"resendEmail(this)\">再次发送</a>";
					}
					contentHtml+="</li>";
					contentHtml+="</ul>";
					contentHtml+="</fieldset>";
				}
				contentHtml+="<fieldset class=\"add_mail pp\">";
				contentHtml+="<legend>添加新邮箱</legend>";
				contentHtml+="<ul>";
				contentHtml+="<li class='email'>";
				contentHtml+="<label>邮箱：</label>";
				contentHtml+="<span class=\"emailval\"><input type='text' class='txt'></span>";
				contentHtml+="</li>";
				contentHtml+="<li>";
				contentHtml+="<span class='err'></span>";
				contentHtml+="</li>";
				contentHtml+="<li>";
				contentHtml+="<a class='addemail' onclick='addEmail(this);'>添加</a>";
				contentHtml+="</li>";
				contentHtml+="</ul>";
				contentHtml+="</fieldset>";
				jQ("#emailinfo_title").nextAll().remove();
		        jQ("#emailinfo_title").after(contentHtml);
			
			}else{
				clip_tips(data.errormsg);
			}
			
		}
	});
}

function bindSinaSNS(){
	var url=window.location.href;
	if(url.indexOf("?")>0){
		url=url.substring(0,url.indexOf("?"));
	}
	jQ.ajax({
		type: "POST",
		url: "userAjax!userCreateSinaOAuth2URL.action",
		data:{
			suffixurl:url
		},
		success:function(data){
			if(data.result){
				window.location.href=data.oauthurl;
			}else{
				alert(data.errormsg);
			}
		}
	});
}

function checkUrlCode(){
	var state=getParameter("state");
	if(state!=null&&typeof(state)!='undefined'&&state=='sina'){
		var code=getParameter("code");
		jQ.ajax({
			type: "POST",
			url:"userAjax!userBindSinacode.action",
			data:{
				code:code
			},
			async:false,
			success:function(data){
				if(data.result){
					window.location.href=jQ("#ctxVal").val()+"/control/userinfo.html";
				}else{
					clip_tips(data.errormsg);
				}
			}
		});
	}
}

function unbindSinaSNS(){
	jQ.ajax({
		type: "POST",
		url: "userAjax!unbindUserSina.action",
		success:function(data){
			if(data.result){
				var tmphtml="";
				tmphtml+="<div class=\"undostatus\">";
				tmphtml+="<span class=\"snsvalbox\">您还未绑定社交账号</span>";
				tmphtml+="<a class=\"bindsns\"></a>";
				tmphtml+="</div>";
				jQ("#cc_isouter").find("label").nextAll().remove();
				jQ("#cc_isouter").find("label").after(tmphtml);
				jQ("#cc_isouter div.undostatus").find("a.bindsns").bind("click",bindSinaSNS);
			}else{
				clip_tips(data.errormsg);
			}
		}
	});
}

function ccinfotoedit(obj){
	var desc=jQ("#cc_desc").data("value");
	var website=jQ("#cc_website").data("value");
	var address=jQ("#cc_address").data("value");
	var addresscode=jQ("#cc_address").data("addresscode");
	var sufaddress=jQ("#cc_address").data("sufaddress");
	jQ("#cc_desc").empty().append("<input type='text' value='"+desc+"'>");
	jQ("#cc_website").empty().append("<input type='text' value='"+website+"'>");
	jQ("#cc_address").empty().append("<div id='preaddressdiv'></div><div><input id='sufaddress' type='text' value='"+sufaddress+"'>")
	var pid=0,cid=0,did=0;
	if(addresscode.length>0){
		if(addresscode.indexOf("_")>0){
			var temparr=addresscode.split("_");
			pid=eval(temparr[0]);
			cid=eval(temparr[1]);
			if(temparr.length>2){
				did=eval(temparr[2]);
			}
		}else{
			pid=eval(addresscode);
		}
	}
	var html="";
	jQ.ajax({
		type: "POST",
		url: "userAjax!loadAllProvinces.action",
		success:function(data){
			if(data.result){
				
				html+="<select>";
				if(pid==0){
					html+="<option value='0' type='0'>";
					html+="请选择";
					html+="</option>";
				}
				var pname,ptype;
				for(var i=0;i<data.provinces.length;i++){
					var province=data.provinces[i];
					var provinceid=province.id;
					var name=province.name;
					var type=province.type;
					if(pid==provinceid){
						pname=name;
						ptype=type;
						html+="<option value='"+provinceid+"' type='"+type+"' selected='selected'>";
					}else{
						html+="<option value='"+provinceid+"' type='"+type+"'>";
					}
					html+=name;
					html+="</option>";
				}
				html+="</select>";
				if(pid==0){
					html+="<select>";
					html+="<option value='0' type='0'>";
					html+="请选择";	
					html+="</option>";
					html+="<select>";
					html+="<select>";
					html+="<option value='0' type='0'>";
					html+="请选择";	
					html+="</option>";
					html+="<select>";
					jQ("#preaddressdiv").append(html);
					initAreaSelect();
					return;
				}
				if(cid==0){
					if(ptype==0){
						jQ.ajax({
							type: "POST",
							url: "userAjax!loadCityByProvinceid.action",
							data:{
								provinceid:pid,
								type:0
							},
							success:function(data){
								if(data.result){
									
									html+="<select>";
									html+="<option value='0' type='0'>";
									html+="请选择";	
									html+="</option>";
									for(var i=0;i<data.cities.length;i++){
										var city=data.cities[i];
										var cityid=city.id;
										var name=city.name;
										var type=city.type;
										if(cityid==cid){
											html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"' selected='selected'>";
										}else{
											html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"'>";
										}
										html+=name;
										html+="</option>";
									}
									html+="</select>";

									html+="<select>";
									html+="<option value='0' type='0'>";
									html+="请选择";
									html+="</option>";
									html+="</select>";
									jQ("#preaddressdiv").append(html);
									initAreaSelect();
									return;
								}
							}
						});
					}else{
						
						html+="<select>";
						html+="<option value='0'>";
						html+=pname;
						html+="</option>";
						html+="</select>";
						jQ.ajax({
							type: "POST",
							url: "userAjax!loadDistrict.action",
							data:{
								cityid:0,
								provinceid:pid
							},
							success:function(data){
								if(data.result){
									html+="<select>";
									if(did==0){
										html+="<option value='0' type='0'>";
										html+="请选择";
										html+="</option>";
									}
									for(var i=0;i<data.districts.length;i++){
										var districts=data.districts[i];
										var districtid=districts.id;
										var name=districts.name;
										var type=districts.type;
										if(districtid==did){
											html+="<option value='"+districtid+"' type='"+type+"' selected='selected'>";
										}else
											html+="<option value='"+districtid+"' type='"+type+"'>";
										html+=name;
										html+="</option>";
									}
									html+="</select>";
									jQ("#preaddressdiv").append(html);
									initAreaSelect();
									return;
								}else{
									alert("数据出错");
								}
							}
						});
					}
				}else{
					jQ.ajax({
						type: "POST",
						url: "userAjax!loadCityByProvinceid.action",
						data:{
							provinceid:pid,
							type:0
						},
						success:function(data){
							if(data.result){
								
								html+="<select>";
								if(cid==0){
									html+="<option value='0' type='0'>";
									html+="请选择";	
									html+="</option>";
								}
								for(var i=0;i<data.cities.length;i++){
									var city=data.cities[i];
									var cityid=city.id;
									var name=city.name;
									var type=city.type;
									if(cityid==cid){
										html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"' selected='selected'>";
									}else{
										html+="<option value='"+cityid+"' pid='"+pid+"' type='"+type+"'>";
									}
									html+=name;
									html+="</option>";
								}
								html+="</select>";
								
								jQ.ajax({
									type: "POST",
									url: "userAjax!loadDistrict.action",
									data:{
										cityid:cid,
										provinceid:pid
									},
									success:function(data){
										if(data.result){
											
											html+="<select>";
											if(did==0){
												html+="<option value='0' type='0'>";
												html+="请选择";
												html+="</option>";
											}
											for(var i=0;i<data.districts.length;i++){
												var districts=data.districts[i];
												var districtid=districts.id;
												var name=districts.name;
												var type=districts.type;
												if(districtid==did){
													html+="<option value='"+districtid+"' type='"+type+"' selected='selected'>";
												}else{
													html+="<option value='"+districtid+"' type='"+type+"'>";
												}
												html+=name;
												html+="</option>";
											}
											html+="</select>";
											jQ("#preaddressdiv").append(html);
											initAreaSelect();
											return;
										}else{
											alert("数据出错");
										}
									}
								});
							}else{
								alert("数据出错");
							}
						}
					});
				}
			}else{
				alert("数据出错");
			}
		}
	});
	var opthtml="";
	opthtml+="<li class=\"separate opt\">";
	opthtml+="<span class=\"errormsg\"></span>";
	opthtml+="<a id='cc_cancel'>取消</a>";
	opthtml+="<a id='cc_confirm'>确定</a>";
	opthtml+="</li>"
	jQ("#ccinfo_ul").append(opthtml);
	jQ("#cc_cancel").bind("click",cancelCCedit);
	jQ("#cc_confirm").bind("click",okCCedit);
	jQ(obj).hide();
}

function initAreaSelect(){
	jQ("#preaddressdiv select").eq(0).change(onProvincesSelect);
	jQ("#preaddressdiv select").eq(1).change(onCitesSelect);
}

function onProvincesSelect(){
	var cityselect=jQ("#preaddressdiv select").eq(1);
	var districtselect=jQ("#preaddressdiv select").eq(2);
	var id=eval(jQ(this).val());
	var type=eval(jQ(this).find("option:selected").attr("type"));
	if(id==0){
		return;
	}else{
		if(type==-1){
			var name=jQ(this).find("option:selected").text();
			cityselect.empty().append("<option type='-1' id='"+id+"'>"+name+"</option>");
			jQ.ajax({
				type: "POST",
				url: "userAjax!loadDistrict.action",
				data:{
					cityid:0,
					provinceid:id
				},
				success:function(data){
					if(data.result){
						districtselect.empty();
						var html="";
						html+="<option value='0' type='0'>";
						html+="请选择";
						html+="</option>";
						for(var i=0;i<data.districts.length;i++){
							var districts=data.districts[i];
							var id=districts.id;
							var name=districts.name;
							var type=districts.type;
							html+="<option value='"+id+"' type='"+type+"'>";
							html+=name;
							html+="</option>";
						}
						districtselect.append(html);
					}else{
						alert("数据出错");
					}
				}
			});
			return;
		}else{
			jQ.ajax({
				type: "POST",
				url: "userAjax!loadCityByProvinceid.action",
				data:{
					provinceid:id,
					type:type
				},
				success:function(data){
					if(data.result){
						cityselect.empty();
						var html="";
						html+="<option value='0' type='0'>";
						html+="请选择";
						html+="</option>";
						for(var i=0;i<data.cities.length;i++){
							var city=data.cities[i];
							var cityid=city.id;
							var name=city.name;
							var type=city.type;
							html+="<option value='"+cityid+"' pid='"+id+"' type='"+type+"'>";
							html+=name;
							html+="</option>";
						}
						cityselect.append(html);
						cityselect.change(onCitesSelect);
					}else{
						alert("数据出错");
					}
				}
			});
		}
	}

}

function onCitesSelect(){
	var id=eval(jQ(this).val()); //cityid
	var pid=eval(jQ(this).find("option:selected").attr("pid"));
	var districtselect=jQ("#preaddressdiv select").eq(2);
	jQ.ajax({
		type: "POST",
		url: "userAjax!loadDistrict.action",
		data:{
			cityid:id,
			provinceid:pid
		},
		success:function(data){
			if(data.result){
				districtselect.empty();
				var html="";
				html+="<option value='0' type='0'>";
				html+="请选择";
				html+="</option>";
				for(var i=0;i<data.districts.length;i++){
					var districts=data.districts[i];
					var id=districts.id;
					var name=districts.name;
					var type=districts.type;
					html+="<option value='"+id+"' type='"+type+"'>";
					html+=name;
					html+="</option>";
				}
				districtselect.append(html);
			}else{
				alert("数据出错");
			}
		}
	});
}

function cancelCCedit(obj){
	jQ("#cclist li.opt").remove();
	jQ("#cc_editbtn").show();
	var desc=jQ("#cc_desc").data("value");
	var website=jQ("#cc_website").data("value");
	var address=jQ("#cc_address").data("value");
	
	jQ("#cc_desc").empty().append(desc);
	jQ("#cc_website").empty().append(website);
	jQ("#cc_address").empty().append(address);
}

function okCCedit(obj){
	jQ("#cc_confirm").unbind("click");
	var pre_address=getPreAddress();
	var suf_address=jQ.trim(jQ("#sufaddress").val());
	if(pre_address!='0'&&suf_address.length<=0){
		jQ("#cc_errorinfo").empty().append("请输入详细地址");
		return;
	}
	var website = jQ.trim(jQ("#cc_website").find("input").val());

	if(website.length>0){
		if(!isURL(website)){
			jQ("#cc_errorinfo").empty().append("请输入正确的网址");
			return;
		}
	}
	var desc=jQ("#cc_desc").find("input").val();
	if(desc.length>50){
		jQ("#cc_errorinfo").empty().append("简介不要超过50字");
		return;
	}
	jQ.ajax({
		type:"POST",
		url:"userAjax!updateCCInfo.action",
		data:{
			desc:desc,
			webSite:website,
			preAddress:pre_address,
			sufAddress:suf_address
		},
		success:function(data){
			if(data.result){
				jQ(obj).parent().hide();
				jQ(obj).parent().prev().show();
				jQ("#cc_desc").empty().append(desc);
				jQ("#cc_desc").data("value",desc);
				jQ("#cc_website").empty().append(website);
				jQ("#cc_website").data("value",website);
				jQ("#cc_address").empty().append(data.address);
				jQ("#cc_address").data("value",data.address);
				jQ("#cc_address").data("addresscode",data.addresscode);
				jQ("#cc_address").data("sufaddress",data.sufaddress);
				jQ("#ccinfo_ul li.opt").remove();
				jQ("#cc_editbtn").show();
				
			}else{
				alert(data.errormsg);
			}
		}
	});
	
}

function getPreAddress(){
	var pselect=jQ("#preaddressdiv select").eq(0);
	var cselect=jQ("#preaddressdiv select").eq(1);
	var dselect=jQ("#preaddressdiv select").eq(2);
	var pval=eval(pselect.val());
	if(pval==0){
		return "0";
	}else{
		var ptype=eval(pselect.find("option:selected").attr("type"));
		if(ptype==-1){
			var cval="0";
			var dval=eval(dselect.val());
			if(dval==0){
				return ""+pval;
			}else{
				return pval+"_0_"+dval;
			}
		}else{
			var cval=eval(cselect.val());
			if(cval==0){
				return ""+pval;
			}else{
				var dval=eval(dselect.val());
				if(dval==0){
					return pval+"_"+cval;
				}else{
					return pval+"_"+cval+"_"+dval;
				}
			}
		}
	}
}

function editEmail(obj){
	var liobj=jQ(obj).parent();
	liobj.empty().append("<a onclick='cancelEmailEdit(this);'>取消</a><a onclick='okEdit(this);'>确定</a>");
	var inputliobj=liobj.prev();
	inputliobj.find("input").attr("disabled",false);
	
}
function okEdit(obj){
	var liobj=jQ(obj).parent();
	var prevliobj=liobj.prev();
	var mailstatus=eval(prevliobj.attr("status"));
	var inputobj=prevliobj.find("input");
	var checkedval=inputobj.attr("checked")?1:0;
	if(mailstatus==checkedval){
		if(eval(mailstatus)==1)
			inputobj.attr("checked",true);
		else
			inputobj.attr("checked",false);
		inputobj.attr("disabled","disabled");
		liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
	}else{
		var ulobj=liobj.parent();
		var emailid=ulobj.attr("emailid");
		jQ.ajax({
			type:"POST",
			url:"controlAjax!updateUserEmail.action",
			data:{
				emailid:emailid,
				emailaccept:checkedval
			},
			success:function(data){
				if(data.result){
					prevliobj.attr("status",checkedval);
					if(eval(checkedval)==1)
						inputobj.attr("checked",true);
					else
						inputobj.attr("checked",false);
					inputobj.attr("disabled","disabled");
					liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
				}else{
					clip_tips(data.errormsg);
				}
			}
		});
	}
}

function cancelEmailEdit(obj){
	var liobj=jQ(obj).parent();
	var prevliobj=liobj.prev();
	var mailstatus=prevliobj.attr("Status");
	var inputobj=prevliobj.find("input");
	if(eval(mailstatus)==1)
		inputobj.attr("checked",true);
	else
		inputobj.attr("checked",false);
	inputobj.attr("disabled","disabled");
	liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"editEmail(this)\">编辑</a>");
}
function deleteEmail(obj){
	var li=jQ(obj).parent().siblings();
	var email = li.eq(1).find("span").eq(1);
	if(email.attr("title")==(email.text()||email.find("input").val())){
		if(email.text()==dataObj['email']){
			clip_tips("不能删除");
			return;
		}else{
			jalert("您确定删除"+email.attr("title")+"这个邮箱吗？",{emailInput:email.attr("title")}, deleteEmail_callback);
		}
	}
}

function saveEmail(obj){
	var email=jQ("#emailinput").val();
	email = jQ.trim(email);
	if(!isEmail(email)){
		clip_tips("请输入正确的邮箱地址格式");
		return;
	}
	var emailadd=jQ("#emailtxt").attr("emailadd");
	if(email==emailadd){
		return;
	}else{
		jQ("#viewopt").attr("title","提示");
		jQ("#viewopt_p").empty().append("原邮箱已经绑定成功，设置新邮箱需要重新验证，是否继续？");
		jQ("#viewopt").dialog({
			buttons: {
				"确定": function() {
	//				var opt=jQ("#viewopt");
	//				var triggerfun=opt.data("function");
	//				opt.trigger(triggerfun);
	//				opt.removeData("function");
	//				jQ("#viewopt_p").hide();
	//				jQ("#viewopt_img").show();
					//activeBtnOnDialog("viewopt",false);
	//				jQ(this).dialog('close');
					updateCCEmail(email);
				},
				"取消": function() {
					jQ("#emailtxt").empty().append(emailadd);
					
					var pageHtml="";
					pageHtml+="<a onclick=\"editEmail(this)\">修改邮箱</a>";
					jQ("#emailbtnline").empty().append(pageHtml);
					jQ(this).dialog('close');
				}
			}
		});
		jQ("#viewopt").parent().css('font', "14px \"Trebuchet MS\", sans-serif");
		jQ("#viewopt").dialog('open');
	}
}
function updateCCEmail(email){
	
	jQ.ajax({
		type:"POST",
		url:"controlAjax!updateCCEmail.action",
		data:{
			emailInput:email
		},
		success:function(data){
			jQ("#viewopt").dialog('close');
			if(data.result){
				clip_tips("验证邮件已发送");
				jQ("#ccemailcontent fieldset.add_mail legend").text("未验证邮箱");
				var pageHtml="";
				pageHtml+="<a onclick=\"editEmail(this)\">修改邮箱</a>";
				jQ("#emailbtnline").empty().append(pageHtml);
				jQ("#email_checkstatus").nextAll().remove();
				jQ("#email_checkstatus").after("<span>验证中…</span><a class=\"wrap\" onclick=\"resendEmail(this)\">重新发送验证</a>");
				jQ("#emailtxt").empty().append(email);
				jQ("#emailtxt").attr("emailadd",email);
				
			}else{
				clip_tips(data.errormsg);
			}
		}
	});
}

function addEmail(obj){
	var liobj=jQ(obj).parent();
	var errorzone=liobj.prev().find("span.err");
	var spanobj=liobj.prevAll("li.email").find("span.emailval");
	var inputobj=spanobj.find("input");
	var emailval=inputobj.val();
	if(emailval.length<=0){
		errorzone.empty().append("请输入邮箱地址");
		return;
	}else if(!isEmail(emailval)){
		errorzone.empty().append("请输入正确的邮箱地址");
		return;
	}
	jQ.ajax({
		type:"POST",
		url:"controlAjax!saveEmail.action",
		data:{
			emailInput:emailval
		},
		success:function(data){
			if(data.result){
				var emailid=data.emailid;
				var ulobj=liobj.parent();
				ulobj.attr("emailid",emailid);
				var fieldsetobj=ulobj.parent();
				fieldsetobj.attr("id","email_"+emailid);
				var titleobj=fieldsetobj.find("legend");
				titleobj.text("未验证邮箱");
				spanobj.empty().append(emailval);
				var errorline=errorzone.parent();
				errorzone.remove();
				errorline.append("<span class='ready'>已发送验证邮件，在<i class='countdown'>60</i>秒后，方可再次验证。</span>");
				liobj.empty().append("<a onclick=\"deleteEmail(this)\">删除</a><a onclick=\"resendEmail(this)\">发送验证</a>");
				errorline.find("i.countdown").data("num",60);
				var scroll=setInterval(function(){
					var num=eval(errorline.find("i.countdown").data("num"));
					num--;
					if(num<1){
						errorline.empty().append("<span class='info'>邮箱地址需要验证</span>");
						clearInterval(scroll);
					}else{
						errorline.find("i.countdown").data("num",num);
						errorline.find("i.countdown").text(num);
					}
				},1000);
				var emailhtml="";
				emailhtml+="<fieldset class=\"add_mail pp\">";
				emailhtml+="<legend>添加新邮箱</legend>";
				emailhtml+="<ul>";
				emailhtml+="<li class='email'>";
				emailhtml+="<label>邮箱：</label>";
				emailhtml+="<span class=\"emailval\"><input type='text' class='txt'></span>";
				emailhtml+="</li>";
				emailhtml+="<li>";
				emailhtml+="<span class='err'></span>";
		        emailhtml+="</li>";
				emailhtml+="<li>";
				emailhtml+="<a class='addemail' onclick='addEmail(this);'>添加</a>";
		        emailhtml+="</li>";
		        emailhtml+="</ul>";
		        emailhtml+="</fieldset>";
		        jQ("#ccemailcontent fieldset:last").after(emailhtml);
		        
			}else{
				clip_tips(data.errormsg);
			}
		}
	});
}
function resendEmail(obj){
	var liobj=jQ(obj).parent();
	var readystatus=liobj.prev().find("span.ready").length;
	var spanobj=liobj.prevAll("li.email").find("span.emailval");
	var email=spanobj.text();
	if(readystatus){
		clip_tips("对不起，60秒内请勿多次请求验证该邮箱地址。");
		return;
	}
	var ulobj=liobj.parent();
	var emailid=ulobj.attr("emailid");
	jQ.ajax({
		type:"POST",
		url:"controlAjax!resendEmail.action",
		data:{
			emailid:eval(emailid)
		},
		success:function(data){
			if(data.result){
				var infoline=liobj.prev();
				infoline.empty().append("<span class='ready'>已发送验证邮件，在<i class='countdown'>60</i>秒后，方可再次验证。</span>");
				infoline.find("i.countdown").data("num",60);
				var scroll=setInterval(function(){
					var num=eval(infoline.find("i.countdown").data("num"));
					num--;
					if(num<1){
						infoline.empty().append("<span class='info'>邮箱地址需要验证</span>");
						clearInterval(scroll);
					}else{
						infoline.find("i.countdown").data("num",num);
						infoline.find("i.countdown").text(num);
					}
				},1000);
			}else{
				clip_tips(data.errormsg);
			}
			
		}
	});
}

function onUploadpicChange(obj){
	var filename=jQ(obj).val();
	if(filename!=null&&filename.length>0){
		var fileext=filename.substr(filename.lastIndexOf(".")+1).toLowerCase();
		if(fileext=='jpg'||fileext=='jpeg'||fileext=='bmp'||fileext=='png'){
			jQ("#demensionuploadbtn").hide();
			jQ("#demensionuploadingdiv").show();
			jQ(obj).parent("form").submit();
		}else{
			clip_tips("二维码图片格式不正确");
		}
	}
}

function demensionUploadCallback(url){
	clip_tips("上传成功");
	jQ("#demensioncodeimg").attr("src",url);
	jQ("#demensionuploadbtn").show();
	jQ("#demensionuploadingdiv").hide();
}

function errorUploadCallback(){
	clip_tips("上传的图片不能超过5M");
}
